package com.xu.cloud.auth.component.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xu.cloud.auth.component.ThirdPartyComponent;
import com.xu.cloud.auth.pojo.domain.CfgThirdPartyLoginDO;
import com.xu.cloud.auth.pojo.mapper.CfgThirdPartyLoginMapper;
import com.xu.cloud.common.util.AssertUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 第三方应用组件实现类
 *
 * @author xuguan
 * @since 2025/2/26
 */
@Component
@Slf4j
public class ThirdPartyComponentImpl implements ThirdPartyComponent {
    @Autowired
    private CfgThirdPartyLoginMapper cfgThirdPartyLoginMapper;

    public CfgThirdPartyLoginDO queryByThirdPartyType(String thirdPartyType) {
        log.info("通过三方应用类型查询第三方应用授权配置表开始, thirdPartyType={}", thirdPartyType);

        AssertUtil.assertHasText(thirdPartyType);
        final CfgThirdPartyLoginDO cfgThirdPartyLoginDo = cfgThirdPartyLoginMapper.selectOne(Wrappers.lambdaQuery(CfgThirdPartyLoginDO.class)
                .eq(CfgThirdPartyLoginDO::getThirdPartyType, thirdPartyType));

        log.info("通过三方应用类型查询第三方应用授权配置表结束, cfgThirdPartyLoginDo={}", cfgThirdPartyLoginDo);
        return cfgThirdPartyLoginDo;
    }

}
